#ifndef SERIALREPEATERWINDOW_H
#define SERIALREPEATERWINDOW_H

#include <QMainWindow>
#include <QtSerialPort>

QT_BEGIN_NAMESPACE
namespace Ui { class SerialRepeaterWindow; }
QT_END_NAMESPACE

class SerialRepeaterWindow : public QMainWindow
{
    Q_OBJECT

public:
    SerialRepeaterWindow(QWidget *parent = nullptr);
    ~SerialRepeaterWindow();

private:
    void loadConfig();
    void loadDefaultConfig();
    bool readConfig();
    void saveConfig();

protected:
    void closeEvent(QCloseEvent *env);

private slots:
    void startActionTriggered();
    void stopActionTriggered();
    void exitActionTriggered();
    void readyReadL();
    void readyReadR();

private:
    QSerialPort *openPort(const QString &port, qint32 baudRate, QSerialPort::DataBits dataBits, QSerialPort::Parity parity, QSerialPort::StopBits stopBits);
    void openEnable(bool enable);

private:
    Ui::SerialRepeaterWindow *ui;
    QSerialPort *m_serialportL, *m_serialportR;

    qint64 m_l2r_cnt;
    qint64 m_r2l_cnt;
};
#endif // SERIALREPEATERWINDOW_H
